"""
    @author:bruceWang
    @desc:规范响应体
    @date:23.9.8
"""

from flask import jsonify




class Result:
    SUCCESS = 200
    CREATED = 201
    ACCEPTED = 202
    NO_CONTENT = 204
    MULTIPLE_CHOICES = 300
    MOVED_PERMANENTLY = 301
    FOUND = 302
    NOT_MODIFIED = 304
    BAD_REQUEST = 400
    UNAUTHORIZED = 401
    FORBIDDEN = 403
    NOT_FOUND = 404
    METHOD_NOT_ALLOWED = 405
    CONFLICT = 409
    INTERNAL_SERVER_ERROR = 500
    NOT_IMPLEMENTED = 501
    BAD_GATEWAY = 502
    SERVICE_UNAVAILABLE = 503
    GATEWAY_TIMEOUT = 504
    HTTP_VERSION_NOT_SUPPORTED = 505

    def __init__(self, success=True, message=None, data=None, status_code=SUCCESS, state=200):
        self.success = success
        self.message = message
        self.data = data
        self.status_code = status_code
        # self.state = state

    def to_dict(self):
        return jsonify({
            'success': self.success,
            'message': self.message,
            'data': self.data,
            'status_code': self.status_code,
            'state': self.status_code
        })
        # },{'Content-Type': 'application/json; charset=utf-8'})
        # }, ensure_ascii=False)

    # def __getattribute__(self):
    #     return self.to_dict(self)

    @staticmethod
    def success(message=None, data=None,state=1):
        return Result(success=True, message=message, data=data, state=state)

    @staticmethod
    def error(message=None, data=None, status_code=INTERNAL_SERVER_ERROR,state=1):
        return Result(success=False, message=message, data=data, status_code=status_code, state=state)


class Response (Result):
    def __init__(self):
        super.__init__(self)
